import http from "@/api";
import { ResPage, User, OrgManager } from "@/api/interface/index";
import qs from "qs";
/**
 * @name 日志管理模块
 */

/**
 * @name 查询在线日志
 */
// 查询在线日志
export const FindUserOnlinePage = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  // return http.post<ResPage<User.ResUserList>>("" + `/pages/itsopUser!findITSOPUserPager.action`, {}, { params });
  return http.postitsm<string>(`/pages/log!userOnlinePage.action`, qs.stringify(newobj));
};

/**
 * @name 查询操作日志
 */
// 查询操作日志
export const FindUserOptPagee = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  // return http.post<ResPage<User.ResUserList>>("" + `/pages/itsopUser!findITSOPUserPager.action`, {}, { params });
  return http.postitsm<string>(`/pages/log!userOptPage.action`, qs.stringify(newobj));
};

/**
 * @name 查询错误日志
 */
// 查询错误日志
export const FinderrLogPage = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  // return http.post<ResPage<User.ResUserList>>("" + `/pages/itsopUser!findITSOPUserPager.action`, {}, { params });
  return http.postitsm<string>(`/pages/log!errLogPage.action`, qs.stringify(newobj));
};

// 下载在线日志数据
export const downloadOnlineLog = (params: OrgManager.ReqOrgManagerParams) => {
  return http.downloaditsm(`/pages/log!downloadOnlineLog.action`, qs.stringify(params));
};

// 下载操作日志数据
export const downloadOptLog = (params: OrgManager.ReqOrgManagerParams) => {
  return http.downloaditsm(`/pages/log!downloadOptLog.action`, qs.stringify(params));
};

// 导出错误日志数据
export const downloadErrLog = (params: OrgManager.ReqOrgManagerParams) => {
  return http.downloaditsm(`/pages/log!downloadErrLog.action`, qs.stringify(params));
};

// 获取用户在线统计页面数据
export const onlineUserJsp = (params: {}) => {
  return http.post<String>(`/pages/common/security/onlineUser.jsp`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 获取用户在线统计页面数据
export const getOnlineUser = () => {
  return http.post<String>(`/pages/request!getOnlineUser.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};
